package cn.catfish.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration// 标识该类为 Spring 配置类
@EnableSwagger2// 启用 Swagger2
public class SwaggerConfig {
    /**
     * 配置第一个 API 分组
     * @return Docket 对象
     */
    @Bean
    public Docket Api1() {
        return new Docket(DocumentationType.SWAGGER_2)// 使用 Swagger 2.0 规范
                .apiInfo(apiInfo())// 设置 API 文档的基本信息
                .groupName("Top1")// 设置分组名称为 "Top1"
                .select()
                .apis(RequestHandlerSelectors.basePackage("cn.catfish.controller"))// 扫描指定包下的控制器
                .paths(PathSelectors.any())// 匹配所有路径
                .build();
    }
    @Bean
    public Docket Api2() {
        return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo())
                .groupName("Top2")
                .select()
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.ant("/error"))
                .build();
    }
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("Catfish 的swagger文档")
                .description("阿玛特纳斯！")
                .contact(new Contact("Catfish", "https://gitee.com/catfish2003/ClassWork1.git", "2026147262@qq.com"))
                .version("1.0")
                .build();
    }
}
